package com.hpf.controller;

import java.util.List;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.hpf.domain.WmsGoods;
import com.hpf.service.IWmsGoodsService;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;

/**
 * 【请填写功能名称】Controller
 * 
 * @author hpf
 * @date 2019-10-11
 */
@Controller
@RequestMapping("/wms/goods")
public class WmsGoodsController extends BaseController
{
    private String prefix = "wms/goods";

    @Autowired
    private IWmsGoodsService wmsGoodsService;

    @RequiresPermissions("wms:goods:view")
    @GetMapping()
    public String goods()
    {
        return prefix + "/goods";
    }

    /**
     * 查询【请填写功能名称】列表
     */
    @RequiresPermissions("wms:goods:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(WmsGoods wmsGoods)
    {
        startPage();
        List<WmsGoods> list = wmsGoodsService.selectWmsGoodsList(wmsGoods);
        return getDataTable(list);
    }

    /**
     * 导出【请填写功能名称】列表
     */
    @RequiresPermissions("wms:goods:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(WmsGoods wmsGoods)
    {
        List<WmsGoods> list = wmsGoodsService.selectWmsGoodsList(wmsGoods);
        ExcelUtil<WmsGoods> util = new ExcelUtil<WmsGoods>(WmsGoods.class);
        return util.exportExcel(list, "goods");
    }

    /**
     * 新增【请填写功能名称】
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存【请填写功能名称】
     */
    @RequiresPermissions("wms:goods:add")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(WmsGoods wmsGoods)
    {
        return toAjax(wmsGoodsService.insertWmsGoods(wmsGoods));
    }

    /**
     * 修改【请填写功能名称】
     */
    @GetMapping("/edit/{goodId}")
    public String edit(@PathVariable("goodId") Long goodId, ModelMap mmap)
    {
        WmsGoods wmsGoods = wmsGoodsService.selectWmsGoodsById(goodId);
        mmap.put("wmsGoods", wmsGoods);
        return prefix + "/edit";
    }

    /**
     * 修改保存【请填写功能名称】
     */
    @RequiresPermissions("wms:goods:edit")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(WmsGoods wmsGoods)
    {
        return toAjax(wmsGoodsService.updateWmsGoods(wmsGoods));
    }

    /**
     * 删除【请填写功能名称】
     */
    @RequiresPermissions("wms:goods:remove")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(wmsGoodsService.deleteWmsGoodsByIds(ids));
    }
}
